home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AECUR100.ARJ / OVERLAY.C < prev    next >
C/C++ Source or Header  |  1990-03-08  |  2KB  |  94 lines

  1. /*------------------------------------------------------------
  2.  * 
  3.  *  overlay.c
  4.  * 
  5.  *  overlay/overwrite one window onto another
  6.  * 
  7.  *  copyright (c) 1987,88,89,90 J. Alan Eldridge
  8.  *
  9.  *----------------------------------------------------------*/
  10.  
  11. #include "curses.h"
  12.  
  13. #define MIN(a,b) (a) < (b) ? (a) : (b)
  14. #define MAX(a,b) (a) > (b) ? (a) : (b)
  15.  
  16. static int
  17. over(win1, win2, zap)
  18. WINDOW *win1, *win2;
  19. char zap;
  20. {
  21.     VIDCHR **buf1,  **buf2;
  22.     int orgy, orgx, org1y, org1x, org2y, org2x, maxy, maxx, max1y, max1x,
  23.         max2y, max2x, pos1y, pos1x, pos2y, pos2x, cursy, cursx;
  24.  
  25.     /* convert to global & intersect */
  26.  
  27.     orgy = MAX(win1->orgy, win2->orgy);
  28.     orgx = MAX(win1->orgx, win2->orgx);
  29.     maxy = MIN(win1->orgy + win1->maxy, win2->orgy + win2->maxy);
  30.     maxx = MIN(win1->orgx + win1->maxx, win2->orgx + win2->maxx);
  31.   
  32.     /* if no intersection, done */
  33.     if (orgy > maxy || orgx > maxx)
  34.         return OK;
  35.  
  36.     /* convert back to local */
  37.     org1y = orgy - win1->orgy;
  38.     org1x = orgx - win1->orgx;
  39.     org2y = orgy - win2->orgy;
  40.     org2x = orgx - win2->orgx;
  41.     max1y = maxy - win1->orgy;
  42.     max1x = maxx - win1->orgx;
  43.     max2y = maxy - win2->orgy;
  44.     max2x = maxx - win2->orgx;
  45.  
  46.     /* set up ptrs */
  47.     buf1 = win1->buf;
  48.     buf2 = win2->buf;
  49.  
  50.     /* save cursor pos & mark starting pt */
  51.     getyx(win2, cursy, cursx);
  52.     wmove(win2, org2y, org2x);
  53.     markwin(win2);
  54.  
  55.     /* copy */
  56.     pos1y = org1y;
  57.     pos2y = org2y;
  58.  
  59.     while (pos1y <= max1y) {
  60.         pos1x = org1x;
  61.         pos2x = org2x;
  62.         while (pos1x <= max1x) {
  63.             if (zap || buf1[pos1y][pos1x].chr != ' ') 
  64.                 buf2[pos2y][pos2x] = buf1[pos1y][pos1x];
  65.             pos1x++;
  66.             pos2x++;
  67.         }
  68.         pos1y++;
  69.         pos2y++;
  70.     }
  71.  
  72.     /* mark ending pt & restore cursor pos */
  73.     wmove(win2, max2y, max2x);
  74.     markwin(win2);
  75.     wmove(win2, cursy, cursx);
  76.     
  77.     return OK;
  78. }
  79.  
  80. int
  81. overlay(win1, win2)
  82. WINDOW *win1, *win2;
  83. {
  84.   return over(win1, win2, 1);
  85. }
  86.  
  87. int
  88. overwrite(win1, win2)
  89. WINDOW *win1, *win2;
  90. {
  91.     return over(win1, win2, 0);
  92. }
  93.  
  94.